package com.ejd.web.vo.genl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;




import javax.faces.bean.ManagedBean;
import javax.faces.bean.ApplicationScoped;
import com.ejd.service.ICarriageService;
import com.ejd.utils.SpringFacesUtil;
import com.ejd.web.bo.impl.Carriage;
import com.ejd.web.constant.SpringBeanConstants;

@ManagedBean(name="existCarriage")
@ApplicationScoped
public class ExistCarriageBean implements java.io.Serializable {

	private List<Carriage> generalItem = new ArrayList<Carriage>();
	private Integer generalSize;
	private List<Carriage> otherItem = new ArrayList<Carriage>();
	private Integer otherSize;
	private List<Carriage> allItem = new ArrayList<Carriage>();
	private Map<String,Carriage> carriageMap = new HashMap<String,Carriage>();

	public ExistCarriageBean() {
		
		ICarriageService<Carriage,Long> applyService = (ICarriageService<Carriage,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.CARRIAGE_SERVICE_BEAN_NAME);
		applyService.setEntityClass(Carriage.class);
		applyService.setPKClass(Long.class);
		List<Carriage> carriages = applyService.getAll("serialNumber", true);
		Map<String,Carriage> tempMap = new HashMap<String,Carriage>();
		if (null != carriages && !(carriages.isEmpty())) {
			for (Carriage carriage:carriages) {
				tempMap.put(carriage.getCarriageId().toString(), carriage);
			}
		}
		this.setCarriageMap(tempMap);
		this.setAllItem(carriages);
		List<Carriage> gcarriages = applyService.findBy("type", "G", "serialNumber", true);
		this.setGeneralItem(gcarriages);
		this.setGeneralSize((null == gcarriages || gcarriages.isEmpty())?0:gcarriages.size());
		List<Carriage> ocarriages = applyService.findBy("type", "O", "serialNumber", true);
		this.setOtherItem(ocarriages);
		this.setOtherSize((null == ocarriages || ocarriages.isEmpty())?0:ocarriages.size());
	}

	public List<Carriage> getGeneralItem() {
		return generalItem;
	}

	public void setGeneralItem(List<Carriage> generalItem) {
		this.generalItem = generalItem;
	}

	public Integer getGeneralSize() {
		return generalSize;
	}

	public void setGeneralSize(Integer generalSize) {
		this.generalSize = generalSize;
	}

	public List<Carriage> getOtherItem() {
		return otherItem;
	}

	public void setOtherItem(List<Carriage> otherItem) {
		this.otherItem = otherItem;
	}

	public Integer getOtherSize() {
		return otherSize;
	}

	public void setOtherSize(Integer otherSize) {
		this.otherSize = otherSize;
	}

	public List<Carriage> getAllItem() {
		return allItem;
	}

	public void setAllItem(List<Carriage> allItem) {
		this.allItem = allItem;
	}

	public Map<String, Carriage> getCarriageMap() {
		return carriageMap;
	}

	public void setCarriageMap(Map<String, Carriage> carriageMap) {
		this.carriageMap = carriageMap;
	}
	
}
